package com.example.content.adapter.recycle

import androidx.annotation.LayoutRes
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.content.DEFAULT_ITEM_TYPE
import com.example.content.adapter.recycle.entity.ItemEntity

/**
 * Created by zhudongao
 * Desc
 * Date 2020/11/8
 */
open class RecyclerAdapter<T>(private val bindListener: BindListener<T>) : BaseMultiItemQuickAdapter<ItemEntity<T>, BaseViewHolder>()  {

    override fun convert(holder: BaseViewHolder, item: ItemEntity<T>) {
        bindListener.convert(holder, item)
    }

    fun addItemViewByType(type: Int, @LayoutRes layoutResId: Int) {
        addItemType(type, layoutResId)
    }

    fun addItemView(@LayoutRes layoutResId: Int) {
        addItemViewByType(DEFAULT_ITEM_TYPE, layoutResId)
    }

    fun updateData(dataList: List<ItemEntity<T>>) {
        this.data.clear()
        this.data.addAll(dataList)
        notifyDataSetChanged()
    }
}